#!/bin/bash

apt-get install python3
apt-get install python3-pip
apt-get install redis-server
apt-get install can-utils

# make sure virtual can bus is set up for testing
modprobe vcan
ip link add dev vcan0 type vcan
ip link set up vcan0

# install python dependencies
pip3 install python-can
pip3 install redis
pip3 install blessed
pip3 install psycopg2-binary

# make binary files executable
chmod +x install
chmod +x scada
chmod +x sorter/sorter.py
chmod +x calibrator/calibrator.py
chmod +x logger/logger.py

# copy binary files to /usr/bin
cp scada /usr/bin/scada
cp sorter/sorter.py /usr/bin/scada_sorter.py
cp calibrator/calibrator.py /usr/bin/scada_calibrator.py
cp logger/logger.py /usr/bin/scada_logger.py

# create a workspace and copy important files into it
mkdir -p /usr/etc/scada
rm -rf /usr/etc/scada/utils
cp -r utils /usr/etc/scada/utils
rm -rf /usr/etc/scada/config
cp -r config /usr/etc/scada/config
cp ./install /usr/etc/scada

# copy service files for systemd
cp sorter/sorter.service /etc/systemd/system
cp calibrator/calibrator.service /etc/systemd/system
cp logger/logger.service /etc/systemd/system
